import { Component, OnInit,ViewChild } from '@angular/core';
// import myTable from '../../document/doc'
import { ClueService } from '../../../../../@core/service/typescript-angular-client/api/clue.service';
import { ActivatedRoute } from '@angular/router';
import { ClueDataService } from '../../../../../@core/service/clue-service/clue-data.service';
import { BizfileService } from '../../../../../@core/service/case-review/doc-service/api/bizfile.service';
import { NzMessageService } from 'ng-zorro-antd/message';
@Component({
  selector: 'app-cluedetail',
  templateUrl: './cluedetail.component.html',
  styleUrls: ['./cluedetail.component.scss']
})

export class CluedetailComponent implements OnInit {
  @ViewChild('clickEvent') myclick;
  docList: any;
  constructor(
    public clues:ClueService,
    public active:ActivatedRoute,
    public bizfileService:BizfileService,
    public message:NzMessageService,
    public clueData:ClueDataService) { }
  public myDoc:any;
  public myflag:boolean;
  public id:any;
  public list:any;
  ngOnInit() { 

    this.clueData.getDepart();

    const editid = this.active.snapshot.params["id"]
    this.clues.getClueById(editid).subscribe((mySucc:any)=>{
      this.list = mySucc.data;
      if(this.list.address){
        this.list.address= JSON.parse( this.list.address);
      }
      if(this.list.caseProvider){
        this.list.caseProvider = JSON.parse(this.list.caseProvider);
      }
      this.docList = JSON.parse(this.list.clueDoc).data;
      this.id = this.list.id;
      
    })  
    
  }
  fun(ev){
    this.myflag = ev;
  }
  openModal(e){
    if(e){
      this.myDoc=e;
      this.myflag = true;
    }else{
      this.myflag = false;
    }
   
  }



  downLoad(fileid,fileName){
    this.bizfileService.downloadFile(fileid).subscribe((res:any) => {
      this.createA2Click(res,fileName)
    }, (error) => { 
      this.message.create('error','文书下载失败！')
    });
  }

  createA2Click(res,fileName){
    const fileURL = URL.createObjectURL(res);
    const a = document.createElement('a');
    a.style.display = 'none';
    a.download = fileName;
    a.href = fileURL;
    a.click();
  }


}
